﻿@model IEnumerable<Car>
@{
    var showMake = true;
    if (bool.TryParse(ViewBag.ByMake?.ToString(), out bool byMake))
    {
        showMake = !byMake;
    }
}
<p>
    <item-create></item-create>
</p>
<table class="table">
    <thead>
    <tr>
        @if (showMake)
        {
            <th>@Html.DisplayNameFor(model => model.MakeId)</th>
        }
        <th>@Html.DisplayNameFor(model => model.Color)</th>
        <th>@Html.DisplayNameFor(model => model.PetName)</th>
        <th>@Html.DisplayNameFor(model => model.Price)</th>
        <th>@Html.DisplayNameFor(model => model.DateBuilt)</th>
        <th>@Html.DisplayNameFor(model => model.IsDrivable)</th>
        <th></th>
    </tr>
    </thead>
    <tbody>
    @foreach (var item in Model)
    {
        <tr>
            @if (showMake)
            {
                <td>@Html.DisplayFor(modelItem => item.MakeNavigation.Name)</td>
            }
            <td>@Html.DisplayFor(modelItem => item.Color)</td>
            <td>@Html.DisplayFor(modelItem => item.PetName)</td>
            <td>@Html.DisplayFor(modelItem => item.Price)</td>
            <td>@Html.DisplayFor(modelItem => item.DateBuilt)</td>
            <td>@Html.DisplayFor(modelItem => item.IsDrivable)</td>
            <td>
                <item-edit item-id="@item.Id"></item-edit> | 
                <item-details item-id="@item.Id"></item-details> | 
                <item-delete item-id="@item.Id"></item-delete>
            </td>
        </tr>
    }
    </tbody>
</table>
